package com.itheima.dubbo.web;

import com.itheima.dubbo.User;
import com.itheima.dubbo.UserFace;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.Method;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
public class UserController {

//    @DubboReference     //dubbo远程服务接口调用注解
//    @DubboReference(cluster = "failfast")     //容错机制的修改
    @DubboReference(check = false)     //启动时不检查服务提供方是否存在
//    @DubboReference(loadbalance = "roundrobin")     //负载均衡策略修改:轮询
//    @DubboReference(version = "1.0.1")     //当使用灰度发布的时候 消费方必须要指定版本号
//    @DubboReference(timeout = 1900)     //【消费方】超时时间注解配置--接口级别
//    @DubboReference(methods = {
//            @Method(name = "getById",timeout = 1500)
//    })     //【消费方】超时时间注解配置--方法级别
    UserFace userFace;


    @GetMapping("hello")
    public String hello(String username){
        return userFace.hello(username);
    }


    @GetMapping("getById")
    public User getById(Long id){
        User user = new User();
        user.setId(id);

        //隐式传参
        RpcContext.getContext().setAttachment("idname","隐式传参");

        return userFace.getById(user);
    }
}
